package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Subject;
import org.hxyjs.entity.Subject;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.SubjectService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/subjectController")
public class SubjectController {
	@Resource
	SubjectService subjectService;
	@RequestMapping("/getAllSubject")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Subject> getAllSubject() throws Exception {
    	System.out.println("查询全部题目");
		return subjectService.getAllSubjects();
    }

	@RequestMapping("/deleteSubjectBySjno/{sjno}")
	@ResponseBody
    public DTO<Subject> deleteSubjectBySjno(@PathVariable("sjno") String sjno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(sjno+"删除题目");
    	return subjectService.deleteSubjectBySjno(sjno);
    }

	@RequestMapping("/updateSubjectBySjno")
	@ResponseBody
	public DTO<Subject> updateSubjectBySjno(@RequestBody Subject subject) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改题目");
		return subjectService.updateSubjectBySjno(subject);
	}


	@RequestMapping("/addSubject")
	@ResponseBody
	public DTO<Subject> addSubject(@RequestBody Subject subject) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加题目");
		System.out.println(subject);
 		return subjectService.addSubject(subject);
	}
	@RequestMapping("/getSubjectByPage")
	@ResponseBody
	public DTO<Subject> getSubjectByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return subjectService.getSubjectByPage(pageInfo);
	}

}